package com.giaothong.model.entity;

import org.json.JSONObject;

import android.text.Html;

import com.giaothong.utils.JSONUtil;
import com.google.android.maps.GeoPoint;

public class StepEntity {
	private DistanceEntity distance;
	private DistanceEntity duration;
	private GeoPoint startLocation;
	private GeoPoint endLocation;
	private String instructions;
	private String travelMode;

	/**
	 * set & get
	 */

	public void setDistance(DistanceEntity distance) {
		this.distance = distance;
	}

	public void setDuration(DistanceEntity duration) {
		this.duration = duration;
	}

	public void setEndLocation(GeoPoint endLocation) {
		this.endLocation = endLocation;
	}

	public void setInstructions(String instructions) {
		this.instructions = instructions;
	}

	public void setStartLocation(GeoPoint startLocation) {
		this.startLocation = startLocation;
	}

	public void setTravelMode(String travelMode) {
		this.travelMode = travelMode;
	}

	public DistanceEntity getDistance() {
		return distance;
	}

	public DistanceEntity getDuration() {
		return duration;
	}

	public GeoPoint getEndLocation() {
		return endLocation;
	}

	public String getInstructions() {
		return instructions;
	}

	public GeoPoint getStartLocation() {
		return startLocation;
	}

	public String getTravelMode() {
		return travelMode;
	}

	/**
	 * column of item
	 */

	public static final String COLUMN_DISTANCE = "distance";
	public static final String COLUMN_DURATION = "duration";
	public static final String COLUMN_END_LOCATION = "end_location";
	public static final String COLUMN_START_LOCATION = "start_location";
	public static final String COLUMN_INSTRUCTION = "html_instructions";
	public static final String COLUMN_TRAVEL_MODE = "travel_mode";

	/**
	 * Unknow of item
	 */
	
	public final DistanceEntity UNKNOW_COLUMN_DISTANCE = new DistanceEntity();
	public final DistanceEntity UNKNOW_COLUMN_DURATION = new DistanceEntity();
	public final GeoPoint UNKNOW_COLUMN_END_LOCATION = new GeoPoint(0, 0);
	public final GeoPoint UNKNOW_COLUMN_START_LOCATION = new GeoPoint(0, 0);
	public final String UNKNOW_COLUMN_INSTRUCTION = "";
	public final String UNKNOW_COLUMN_TRAVEL_MODE = "";

	/**
	 * contructor defaut
	 */
	public StepEntity() {
		setDefautValue();
	}

	/**
	 * contructor
	 * 
	 * @param jsonObject
	 */
	public StepEntity(JSONObject jsonObject) {
		setDefautValue();
		if (jsonObject == null)
			return;

		this.distance = new DistanceEntity(JSONUtil.jsonObjectTryGetValue(jsonObject, COLUMN_DISTANCE));
		this.duration = new DistanceEntity(JSONUtil.jsonObjectTryGetValue(jsonObject, COLUMN_DURATION));
		this.startLocation = JSONUtil.geoPointTryGetValue(jsonObject, COLUMN_START_LOCATION);
		this.endLocation = JSONUtil.geoPointTryGetValue(jsonObject, COLUMN_END_LOCATION);
		// remove tag in html
		this.instructions = Html.fromHtml(JSONUtil.stringTryGetValue(jsonObject, COLUMN_INSTRUCTION)).toString();
		this.travelMode = JSONUtil.stringTryGetValue(jsonObject, COLUMN_TRAVEL_MODE);

	}

	/**
	 * set defaut value
	 */
	public void setDefautValue() {
		this.distance = UNKNOW_COLUMN_DISTANCE;
		this.duration = UNKNOW_COLUMN_DURATION;
		this.endLocation = UNKNOW_COLUMN_END_LOCATION;
		this.startLocation = UNKNOW_COLUMN_START_LOCATION;
		this.instructions = UNKNOW_COLUMN_INSTRUCTION;
		this.travelMode = UNKNOW_COLUMN_TRAVEL_MODE;
	}

}
